package com.qf.votedemo.phone.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.votedemo.phone.entity.Phone;
import com.qf.votedemo.phone.mapper.PhoneMapper;
import com.qf.votedemo.phone.service.IPhoneService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lx
 * @since 2023-02-24
 */
@Service
public class PhoneServiceImpl extends ServiceImpl<PhoneMapper, Phone> implements IPhoneService {

    /**
     * 号码落库
     *
     * @param phoneNum
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void savePhone(String phoneNum) {
        Phone phone = new Phone();
        phone.setPhonenumber(phoneNum);
        save(phone);
    }

    /**
     * 查询号码是否有效
     *
     * @param phoneNum
     * @return
     */
    @Override
    public Phone selectPhone(String phoneNum) {
        Phone phoneDb = getOne(new LambdaQueryWrapper<Phone>().eq(Phone::getPhonenumber, phoneNum));
        return phoneDb;
    }
}
